package com.song.gencode.controller;

import javax.servlet.ServletException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.song.gencode.service.GencodeService;

import basic.base.web.BaseController;
import basic.commons.util.DownloadUtil;
import basic.commons.util.StringUtil;

/**
 * Created by keyuwang on 2016/11/29.
 */

@Controller
@RequestMapping(value = "/pem/gencode")
public class GencodeController extends BaseController {
    @Autowired
    private GencodeService service;

    @RequestMapping("/genCode")
    public void genCode(String tableName,String packageName) throws Exception {
        String zipPath = service.gencode(tableName,packageName);
        if(StringUtil.isNotEmpty(zipPath)){
            try {
                DownloadUtil.downloadPublic(zipPath, getResponse(), getRequest());
            } catch (ServletException e) {
                e.printStackTrace();
            }
        }
    }
    @RequestMapping("/init")
    public ModelAndView init() throws Exception {
    	ModelAndView mv = new ModelAndView("/gencode/index");
		return mv;
    }

}
